{% extends "base.html" %}
{% load staticfiles %}

{% block title %}
图灵课程 - 考试问题详情
{% endblock %}

{% block style %}

{% endblock %}

{% block content %}

<div class="container ExamQuestion" align="center">
    <h3 class="transition_appointment">考试问题</h3>
    <br>
    <form action="/OnlineExam/Result/"  method="POST" onsubmit="return checkForm(this)">
        {% for question in questions %}
        {% if question.type1 %}
        <div class="examdetail">
            <span>{{question.QuestionTitle}}</span>
            <ul>
                <li><input type="radio" name="{{question.QuestionID}}" value="A">A. {{question.OptionA}}</li>
                <li><input type="radio" name="{{question.QuestionID}}" value="B">B. {{question.OptionB}}</li>
                <li><input type="radio" name="{{question.QuestionID}}" value="C">C. {{question.OptionC}}</li>
                <li><input type="radio" name="{{question.QuestionID}}" value="D">D. {{question.OptionD}}</li>
            </ul>
        </div>
        <br>
        {% endif %}
        {% if question.type2 %}
        <div class="examdetail">
            <span>{{question.QuestionTitle}}</span>
            <ul>
                <li><input type="radio" name="{{question.QuestionID}}" value="A">True</li>
                <li><input type="radio" name="{{question.QuestionID}}" value="B">False</li>
            </ul>
        </div>
        <br>
        {% endif %}
        {% endfor %}
        <input type="submit" value="结束答题" class="upload-button">
    </form>
</div>
{% endblock %}
{% block other_script %}
<script language="javascript">
    Array.prototype.myUnique = function()
    {
        this.sort();

        var re=[];
        for(var i = 0; i < this.length; i++)
        {
            if( this[i] !== re[re.length-1] && this[i] != "")
            {
                re.push(this[i]);
            }
        }
        return re;
    }
    var nameList = [];
    getAllName();
    //    if(typeof jQuery!=='undefined'){
    //        alert('jQuery Loaded');
    //    }
    //    else{
    //        alert('not loaded yet');
    //    }
    function getAllName() {
        $(":input").each(function () {
            nameList.push(this.name);
        });
        nameList = nameList.myUnique();
    }

    var counter = 0;
    function checkForm(obj) {
        var allChecked = true;
        nameList.forEach(function (item) {
            counter = 0;
            var inputRadios = $("input[name="+item+"]");
            inputRadios.each(function () {
                if(this.checked == false) {
                    counter++;
                }
            })
            if(counter == inputRadios.length) {
                allChecked = false;
            }
        })
        if (!allChecked) {
            alert("请将全部题目都进行作答后再提交答案！");
            return false
        }
        else
          return confirm("确定要提交答案吗?");

    }
</script>
<!--<button onclick="val = $('input:radio:checked');
var answer = new Array();
var id = new Array();
for (var i =0;i<val.length;i++)
  		{
  			answer[i] = val[i].value;
        id[i] = val[i].getAttribute('name')
  		}


$.ajax({
  target: '#'+quest
  url: '/OnlineExam/AnswerQuestion/',
  type: 'POST',
  dataType: 'json',
  traditional: true,
  data: {
  	answer:JSON.stringify(answer),
    length:i,
    examid:JSON.stringify(id)
  },

  success:function(data){
    alert(data);
    window.location.reload()
  }
});">提交</button>
-->

{% endblock %}
